//package com.zj.core.services
//
//import android.content.BroadcastReceiver
//import android.content.Context
//import android.content.Intent
//import android.os.Bundle
//import android.util.Log
//import cn.jpush.android.api.JPushInterface
//import com.zj.core.activity.MainActivity
//import org.json.JSONException
//import com.zj.core.activity.NotificationActivity
//import org.json.JSONObject
//
//class JpushReceiver : BroadcastReceiver() {
//    override fun onReceive(context: Context, intent: Intent) {
//        val bundle = intent.extras
//
//        if (JPushInterface.ACTION_REGISTRATION_ID == intent.action) {
//            val regId = bundle!!.getString(JPushInterface.EXTRA_REGISTRATION_ID)
//            Log.d(TAG, "[MyReceiver] 接收Registration Id : " + regId!!)
//            //send the Registration Id to your server...
//
//        } else if (JPushInterface.ACTION_MESSAGE_RECEIVED == intent.action) {
//            Log.d(TAG, "[MyReceiver] 接收到推送下来的自定义消息: " + bundle!!.getString(JPushInterface.EXTRA_MESSAGE)!!)
//            //processCustomMessage(context, bundle)
//
//        } else if (JPushInterface.ACTION_NOTIFICATION_RECEIVED == intent.action) {
//            Log.d(TAG, "[MyReceiver] 接收到推送下来的通知")
//            val notifactionId = bundle!!.getInt(JPushInterface.EXTRA_NOTIFICATION_ID)
//            Log.d(TAG, "[MyReceiver] 接收到推送下来的通知的ID: $notifactionId")
//
//        } else if (JPushInterface.ACTION_NOTIFICATION_OPENED == intent.action) {
//            Log.d(TAG, "[MyReceiver] 用户点击打开了通知")
//            //打开自定义的Activity
//            val i =Intent(context, NotificationActivity().javaClass)
//            i.putExtras(bundle)
//            //i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
//            i.flags=Intent.FLAG_ACTIVITY_NEW_TASK and Intent.FLAG_ACTIVITY_CLEAR_TOP
//            context.startActivity(i)
//        } else if (JPushInterface.ACTION_RICHPUSH_CALLBACK == intent.action) {
//            Log.d(TAG, "[MyReceiver] 用户收到到RICH PUSH CALLBACK: " + bundle!!.getString(JPushInterface.EXTRA_EXTRA)!!)
//            //在这里根据 JPushInterface.EXTRA_EXTRA 的内容处理代码，比如打开新的Activity， 打开一个网页等..
//
//        } else if (JPushInterface.ACTION_CONNECTION_CHANGE == intent.action) {
//            val connected = intent.getBooleanExtra(JPushInterface.EXTRA_CONNECTION_CHANGE, false)
//            Log.w(TAG, "[MyReceiver]" + intent.action + " connected state change to " + connected)
//        } else {
//            Log.d(TAG, "[MyReceiver] Unhandled intent - " + intent.action!!)
//        }
//    }
//
//    //send msg to MainActivity
////    private fun processCustomMessage(context: Context, bundle: Bundle) {
////              if (MainActivity.isForeground) {
////                  String message = bundle.getString(JPushInterface.EXTRA_MESSAGE);
////                  String extras = bundle.getString(JPushInterface.EXTRA_EXTRA);
////                  Intent msgIntent = new Intent(MainActivity.MESSAGE_RECEIVED_ACTION);
////                  msgIntent.putExtra(MainActivity.KEY_MESSAGE, message);
////                  if (!ExampleUtil.isEmpty(extras)) {
////                      try {
////                          JSONObject extraJson = new JSONObject(extras);
////                          if (null != extraJson && extraJson.length() > 0) {
////                              msgIntent.putExtra(MainActivity.KEY_EXTRAS, extras);
////                          }
////                      } catch (JSONException e) {
////
////                      }
////
////                  }
////                  context.sendBroadcast(msgIntent)
////              }
////    }
//
//    companion object {
//        private val TAG = "JPush"
//        // 打印所有的 intent extra 数据
//        private fun printBundle(bundle: Bundle): String {
//            val sb = StringBuilder()
//            for (key in bundle.keySet()) {
//                if (key == JPushInterface.EXTRA_NOTIFICATION_ID) {
//                    sb.append("\nkey:" + key + ", value:" + bundle.getInt(key))
//                } else if (key == JPushInterface.EXTRA_CONNECTION_CHANGE) {
//                    sb.append("\nkey:" + key + ", value:" + bundle.getBoolean(key))
//                } else if (key == JPushInterface.EXTRA_EXTRA) {
//                    if (bundle.getString(JPushInterface.EXTRA_EXTRA)!!.isEmpty()) {
//                        Log.i(TAG, "This message has no Extra data")
//                        continue
//                    }
//
//                    try {
//                        val json = JSONObject(bundle.getString(JPushInterface.EXTRA_EXTRA))
//                        val it = json.keys()
//
//                        while (it.hasNext()) {
//                            val myKey = it.next().toString()
//                            sb.append(
//                                "\nkey:" + key + ", value: [" +
//                                        myKey + " - " + json.optString(myKey) + "]"
//                            )
//                        }
//                    } catch (e: JSONException) {
//                        Log.e(TAG, "Get message extra JSON error!")
//                    }
//
//                } else {
//                    sb.append("\nkey:" + key + ", value:" + bundle.getString(key))
//                }
//            }
//            return sb.toString()
//        }
//    }
//}
